var app = getApp();

Page({
    data: { 
        protocolList:[],
        protocolArr:[],
        pageCurrent:1,
        pageNum:"",  //总页数
        loading:false,   //"上拉加载中"
        loadingComplete:false   //"加载完成"
    },
    onLoad: function () {
        var that = this;
        that.setData({
            navH: app.globalData.navHeight
        });
        that.getProtocolList();
    },
    navBack: function () {
        wx.navigateBack({
            delta: 1
        })
    },
    getProtocolList: function () {
        var that = this;
        wx.request({
            url: app.globalData.apiHost + "/api/terms/termsList",
            data: {
                page:that.data.pageCurrent,
                pagesize:12
            },
            header: {
                'content-type': 'application/x-www-form-urlencoded',
            },
            method: "POST",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {
                    var listPageNum = res.data.data.last_page;
                    for (var i = 0; i < res.data.data.data.length; i++) { 
                        that.data.protocolList.push(res.data.data.data[i]);
                    }
                    var listData = that.data.protocolList;
                    that.setData({
                        protocolArr: listData,
                        pageNum:listPageNum
                    })
                    
                }
            },
            
        });
    },
    onReachBottom: function () {
        let that = this;
        if (that.data.pageCurrent < that.data.pageNum) {
            that.setData({
                loading:true,
                loadingComplete:false,
                pageCurrent: that.data.pageCurrent + 1
            })
            that.getHelpList();
        }else if(that.data.pageCurrent >= that.data.pageNum){
            that.setData({
                loading:false,
                loadingComplete:true
            })
        }
    }
})

